package org.ace.logic.user;

import io.netty.channel.Channel;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.ace.Manager.interfaces.IHandlerManager;
import org.ace.endingCode.SocketModel;
import org.ace.logic.IHandlerServ;
import org.ace.logic.IoHandler;
import org.ace.logic.user.protocol.UserProtocol;

public abstract class UserHandler implements IoHandler {

	//根据区域码，划分不同的模块 switch 模式
//	private IHandlerServ player;
//	private IHandlerServ equi;
//	private IHandlerServ item;
	
	//使用handlerManager管理,userhandler下面的handler类
	private IHandlerManager manager;

	//程序启动调用
	@PostConstruct
	void init(){
		manager.register(UserProtocol.AREA_PLAYER, createPlayerHandler());
		manager.register(UserProtocol.AREA_TEAM, createTeamHandler());
		manager.register(UserProtocol.AREA_ITEM, createItemHandler());
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public void messageReceived(Channel channel, SocketModel message) {
		//也可以通过 , switch 将消息分发 注入的 各个模块
		manager.get(message.getArea()).messageReceived(channel, message);
	}

	@Override
	public void channelClose(Channel channel) {
		
		manager.get(UserProtocol.AREA_PLAYER).Colse(channel);
	}
	
	public abstract IHandlerServ createPlayerHandler();	
	public abstract IHandlerServ createTeamHandler();	
	public abstract IHandlerServ createItemHandler();	
	public abstract IHandlerServ createShopHandler();	
	
	//public abstract IHandlerServ createCoinTreeHandler();
    //public abstract IHandlerServ createCosplayHandler();
	//通过 这种配法将manager 和userManager关联,也可以在userHandler 下面配置属性
	@Resource(name="userManager")
	protected void setManager(IHandlerManager manager){
		this.manager=manager;
	}
	
	@Override
	public void onShake(Channel channel) {
		// 
		
	}

}
